import Vue from 'vue'
import { User } from 'classes/user'
import { getUser } from 'service/user'

const __user = Vue.observable(new User())

export const __setUser = (user) => {
  Object.keys(__user).forEach(key => {
    __user[key] = user[key]
  })
}

export const __getUser = () => {
  if (!__user.username) {
    getUser()
  }
  return __user
}

export const __getUserAs = async () => {
  if (!__user.username) {
    try {
      await getUser()
    } catch {}
  }
  return __user
}
